package com.heima.wemedia.controller.v1;

import com.heima.model.common.constants.wemedia.WemediaContans;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dtos.WmMaterialDto;
import com.heima.wemedia.service.WmMaterialService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author huan
 * @serial 每天一百行, 致敬未来的自己
 * @Description
 */
@RestController
@RequestMapping("/api/v1/material")
@Api(value = "自媒体素材管理", tags = "自媒体素材管理")
public class WmMaterialController {
    @Autowired
    private WmMaterialService wmMaterialService;

    @PostMapping("/upload_picture")
    @ApiOperation("自媒体素材图片上传")
    public ResponseResult uploadPicture(MultipartFile multipartFile) {
        return wmMaterialService.uploadPicture(multipartFile);
    }


    @PostMapping("/list")
    @ApiOperation("自媒体图片列表查询")
    public ResponseResult findList(@RequestBody WmMaterialDto dto) {
        return wmMaterialService.findList(dto);
    }


    @GetMapping("/del_picture/{id}")
    @ApiOperation("根据id删除图片")
    public ResponseResult delPictureById(@PathVariable Long id) {
        return wmMaterialService.delPictureById(id);
    }


    @GetMapping("/cancel_collect/{id}")
    @ApiOperation("收藏素材图片")
    public ResponseResult cancelCollectionMaterial(@PathVariable Long id) {
        return wmMaterialService.updateStatus(id, WemediaContans.CANCEL_COLLECT_MATERIAL);
    }

    @GetMapping("/collect/{id}")
    @ApiOperation("取消收藏素材图片")
    public ResponseResult collectionMaterial(@PathVariable Long id) {
        return wmMaterialService.updateStatus(id, WemediaContans.COLLECT_MATERIAL);
    }
}
